
#include "stdneb.h"
#include "exception.h"
#include "logManager.h"

namespace Core 
{
using namespace Util;

Exception::Exception(int num, const String& desc, const String& src) :
    line( 0 ),
    number( num ),
    description( desc ),
    source( src )
{
    // Log this error - not any more, allow catchers to do it
    //LogManager::getSingleton().logMessage(this->getFullDescription());
}

Exception::Exception(int num, const String& desc, const String& src, 
	const char* typ, const char* fil, long lin) :
    line( lin ),
    number( num ),
	typeName(typ),
    description( desc ),
    source( src ),
    file( fil )
{
    // Log this error, mask it from debug though since it may be caught and ignored
    if(LogManager::HasInstance())
	{
        LogManager::Instance()->logMessage(
			this->getFullDescription(), 
            LML_CRITICAL, true);
	}

}

Exception::Exception(const Exception& rhs)
    : line( rhs.line ), 
	number( rhs.number ), 
	typeName( rhs.typeName ), 
	description( rhs.description ), 
	source( rhs.source ), 
	file( rhs.file )
{
}

void Exception::operator = ( const Exception& rhs )
{
    description = rhs.description;
    number = rhs.number;
    source = rhs.source;
    file = rhs.file;
    line = rhs.line;
	typeName = rhs.typeName;
}

const Util::String& Exception::getFullDescription(void) const
{
	fullDesc.Format("PHILOTES EXCEPTION(%d:%s):%s in %s",number,typeName.AsCharPtr(),description.AsCharPtr(),source.AsCharPtr());
	if( line > 0 )
	{
		Util::String str;
		str.Format(" at %s (line %d)",file.AsCharPtr(),line);
		fullDesc.Append(str);
	}

	return fullDesc;
}

int Exception::getNumber(void) const throw()
{
    return number;
}

}

